package it.unisa.dao.implementation;

import java.util.List;

import it.unisa.beans.Comment;
import it.unisa.beans.Contour;
import it.unisa.beans.Photo;
import it.unisa.dao.ContourDao;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class ContourHibernateDao extends HibernateDaoSupport implements ContourDao {

	public void insert(Contour contour) {
		getHibernateTemplate().saveOrUpdate(contour);
	}

	public void update(Contour contour) {
		getHibernateTemplate().saveOrUpdate(contour);
		
	}

	public void delete(String url) {
		Contour c=new Contour();
		c.setUrl_contour(url);
		
	}

	public List<Contour> findAllContours() {
		return getHibernateTemplate().find("from Contour");

	}

	public int contourCount() {
		// TODO Auto-generated method stub
		return findAllContours().size();
	}

	public List<Contour> find(Contour contour) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Photo.class);
		if(contour.getPhoto()!=null)
			criteria.add(Restrictions.eq("photo", contour.getPhoto()));
		return (List<Contour>)getHibernateTemplate().findByCriteria(criteria);		
	}

	

}
